package 力扣日常刷题.木23一月.第14天314;

/**
 * @author 帅小伙
 * @date 2022/3/14
 * @description
 */
public class Demo64乘积最大数组 {

    public int maxProduct(int[] nums) {
        int maxF = nums[0],minF = nums[0],ans = nums[0];
        int length = nums.length;
        for (int i = 1; i < length; i++) {
            int mx = maxF,mn = minF;
            maxF = Math.max(nums[i],Math.max(mx*nums[i],mn * nums[i]));
            minF = Math.min(nums[i],Math.min(mx*nums[i],mn * nums[i]));
            ans = Math.max(maxF,minF);
        }
        return ans;
    }

}
